cmake_minimum_required( VERSION 2.6 )
project("QMyMemory ")

SET (CMAKE_BUILD_TYPE Release)

IF(NOT MSVC)
    IF("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64")
        SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
    ENDIF("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64")
ENDIF()

if(${CMAKE_SYSTEM_NAME} STREQUAL Linux)
    set (QGT_L10N_DIRECTORY ${CMAKE_INSTALL_PREFIX}/share/qmymemory/l10n)
endif(${CMAKE_SYSTEM_NAME} STREQUAL Linux)

if(${CMAKE_SYSTEM_NAME} STREQUAL FreeBSD)
 set (QGT_L10N_DIRECTORY ${CMAKE_INSTALL_PREFIX}/share/qmymemory/l10n)
endif(${CMAKE_SYSTEM_NAME} STREQUAL FreeBSD)


ADD_DEFINITIONS(${QT_DEFINITIONS})
ADD_DEFINITIONS(-DQT_NETWORK)
ADD_DEFINITIONS(-DUNICODE)

find_package(Qt4 REQUIRED)
include(${QT_USE_FILE})



include_directories(
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_INCLUDE_PATH})

add_subdirectory(src/3rdparty/qxtshortcut)
add_subdirectory(src/3rdparty/qxtjson)
#add_subdirectory(src/3rdparty/qtsingleapplication)

configure_file(src/defines.h.in defines.h)


set(HEADERS
src/mainwindow.h
src/hackedtextedit.h
src/logger.h
src/wordsreservation.h
src/tooltip.h
src/trayicon.h
src/translate.h
src/pronounce.h
src/settings.h
src/about.h
)


set(SOURCES
src/main.cpp
src/mainwindow.cpp
src/hackedtextedit.cpp
src/logger.cpp
src/wordsreservation.cpp
src/tooltip.cpp
src/trayicon.cpp
src/translate.cpp
src/pronounce.cpp
src/settings.cpp
src/about.cpp
)

set(FORMS
src/mainwindow.ui
src/logger.ui
src/wordsreservation.ui
src/settings.ui
src/about.ui)


set(RESOURCES src/resources.qrc)

set (FILES_TO_TRANSLATE ${SOURCES} ${HEADERS} ${FORMS})




qt4_wrap_cpp(MOC_SOURCES ${HEADERS})
qt4_wrap_ui(UI_HEADERS ${FORMS})


qt4_add_resources(QRC_SOURCES ${RESOURCES})


# Translation files
#file (GLOB TRANSLATIONS_FILES src/l10n/*.ts)
set (TRANSLATIONS_FILES
	src/l10n/English.ts
	src/l10n/Russian.ts
	src/l10n/Ukrainian.ts
	src/l10n/Japanese.ts
)

option (UPDATE_TRANSLATIONS "Update source translation src/l10n/*.ts files (WARNING: make clean will delete the source .ts files! Danger!)")
if (UPDATE_TRANSLATIONS)
  qt4_create_translation(QM_FILES ${FILES_TO_TRANSLATE} ${TRANSLATIONS_FILES})
else (UPDATE_TRANSLATIONS)
  qt4_add_translation(QM_FILES ${TRANSLATIONS_FILES})
endif (UPDATE_TRANSLATIONS)

add_custom_target (lupdate DEPENDS ${QM_FILES})


add_executable(qmymemory ${SOURCES}
	       ${MOC_SOURCES} ${UI_HEADERS} ${QM_FILES} ${QRC_SOURCES})

    target_link_libraries(qmymemory  "/usr/lib/libX11.so")

if (Q_WS_X11)
    include_directories(${X11_Xlib_INCLUDE_PATH} )
    target_link_libraries(qmymemory ${X11_LIBRARIES})
endif (Q_WS_X11)


target_link_libraries(qmymemory ${QT_LIBRARIES} ${QT_QTNETWORK_LIBRARIES}  qxtjson qxtshortcut )



# install for linux
if(${CMAKE_SYSTEM_NAME} STREQUAL Linux)
        configure_file(${CMAKE_CURRENT_SOURCE_DIR}/qmymemory.desktop ${CMAKE_CURRENT_BINARY_DIR}/qmymemory.desktop COPYONLY)
        configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/artwork/icons/eyeworld_icon.png ${CMAKE_CURRENT_BINARY_DIR}/qmymemory.png COPYONLY)

        install(TARGETS qmymemory DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
        install(FILES ${CMAKE_CURRENT_BINARY_DIR}/qmymemory.desktop  DESTINATION ${CMAKE_INSTALL_PREFIX}/share/applications)
        install(FILES ${CMAKE_CURRENT_BINARY_DIR}/qmymemory.png  DESTINATION ${CMAKE_INSTALL_PREFIX}/share/pixmaps)
	install(FILES ${QM_FILES} DESTINATION ${QGT_L10N_DIRECTORY})
endif()


# install for freebsd
if(${CMAKE_SYSTEM_NAME} STREQUAL FreeBSD)
 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/qmymemory.desktop ${CMAKE_CURRENT_BINARY_DIR}/qmymemory.desktop COPYONLY)
 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/artwork/icons/eyeworld_icon.png ${CMAKE_CURRENT_BINARY_DIR}/qmymemory.png COPYONLY)
 install(TARGETS qmymemory DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/qmymemory.desktop DESTINATION ${CMAKE_INSTALL_PREFIX}/share/applications)
 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/qmymemory.png DESTINATION ${CMAKE_INSTALL_PREFIX}/share/pixmaps)
 install(FILES ${QM_FILES} DESTINATION ${QGT_L10N_DIRECTORY})
endif()

if(${CMAKE_SYSTEM_NAME} STREQUAL Darwin)
endif()

if(${CMAKE_SYSTEM_NAME} STREQUAL Windows)
endif()
